load("//:build_variables.bzl", "COPTS")

package(
    default_visibility = ["//:android_cuttlefish"],
)

proto_library(
    name = "libadb_protos",
    srcs = [
        "proto/adb_host.proto",
        "proto/adb_known_hosts.proto",
        "proto/app_processes.proto",
        "proto/key_type.proto",
        "proto/pairing.proto",
    ],
    strip_import_prefix = "proto",
)

cc_proto_library(
    name = "libadb_cc_protos",
    deps = [":libadb_protos"],
)

cc_binary(
    name = "adb",
    srcs = [
        "adb.cpp",
        "adb.h",
        "adb_auth.h",
        "adb_io.cpp",
        "adb_io.h",
        "adb_listeners.cpp",
        "adb_listeners.h",
        "adb_mdns.cpp",
        "adb_mdns.h",
        "adb_trace.cpp",
        "adb_trace.h",
        "adb_unique_fd.cpp",
        "adb_unique_fd.h",
        "adb_utils.cpp",
        "adb_utils.h",
        "adb_wifi.h",
        "apacket_reader.cpp",
        "apacket_reader.h",
        "client/adb_client.cpp",
        "client/adb_client.h",
        "client/adb_install.cpp",
        "client/adb_install.h",
        "client/adb_wifi.cpp",
        "client/auth.cpp",
        "client/bugreport.cpp",
        "client/bugreport.h",
        "client/commandline.cpp",
        "client/commandline.h",
        "client/console.cpp",
        "client/detach.cpp",
        "client/detach.h",
        "client/discovered_services.cpp",
        "client/discovered_services.h",
        "client/file_sync_client.cpp",
        "client/file_sync_client.h",
        "client/host_services.h",
        "client/incremental.cpp",
        "client/incremental.h",
        "client/incremental_server.cpp",
        "client/incremental_server.h",
        "client/incremental_utils.cpp",
        "client/incremental_utils.h",
        "client/line_printer.cpp",
        "client/line_printer.h",
        "client/main.cpp",
        "client/mdns_tracker.cpp",
        "client/mdns_tracker.h",
        "client/mdns_utils.cpp",
        "client/mdns_utils.h",
        "client/openscreen/mdns_service_info.cpp",
        "client/openscreen/mdns_service_info.h",
        "client/openscreen/platform/logging.cpp",
        "client/openscreen/platform/task_runner.cpp",
        "client/openscreen/platform/task_runner.h",
        "client/openscreen/platform/udp_socket.cpp",
        "client/pairing/pairing_client.cpp",
        "client/pairing/pairing_client.h",
        "client/transport_client.h",
        "client/transport_emulator.cpp",
        "client/transport_mdns.cpp",
        "client/transport_usb.cpp",
        "client/usb.h",
        "client/usb_libusb.cpp",
        "client/usb_libusb.h",
        "client/usb_libusb_device.cpp",
        "client/usb_libusb_device.h",
        "client/usb_libusb_hotplug.cpp",
        "client/usb_libusb_hotplug.h",
        "client/usb_libusb_inhouse_hotplug.cpp",
        "client/usb_libusb_inhouse_hotplug.h",
        "client/usb_linux.cpp",
        "crypto/include/adb/crypto/key.h",
        "crypto/include/adb/crypto/rsa_2048_key.h",
        "crypto/include/adb/crypto/x509_generator.h",
        "crypto/key.cpp",
        "crypto/rsa_2048_key.cpp",
        "crypto/x509_generator.cpp",
        "compression_utils.h",
        "diagnose_usb/diagnose_usb.cpp",
        "diagnose_usb/include/diagnose_usb.h",
        "fdevent/fdevent.cpp",
        "fdevent/fdevent.h",
        "fdevent/fdevent_epoll.cpp",
        "fdevent/fdevent_epoll.h",
        "file_sync_protocol.h",
        "incfs/util/map_ptr.h",
        "libcrypto_utils/android_pubkey.cpp",
        "libcrypto_utils/include/crypto_utils/android_pubkey.h",
        "pairing_auth/aes_128_gcm.cpp",
        "pairing_auth/include/adb/pairing/aes_128_gcm.h",
        "pairing_auth/include/adb/pairing/pairing_auth.h",
        "pairing_auth/pairing_auth.cpp",
        "pairing_connection/include/adb/pairing/pairing_connection.h",
        "pairing_connection/pairing_connection.cpp",
        "services.cpp",
        "services.h",
        "shell_protocol.h",
        "shell_service_protocol.cpp",
        "socket.h",
        "sockets.cpp",
        "socket_spec.cpp",
        "socket_spec.h",
        "sysdeps.h",
        "sysdeps/chrono.h",
        "sysdeps/env.cpp",
        "sysdeps/env.h",
        "sysdeps/errno.cpp",
        "sysdeps/errno.h",
        "sysdeps/network.h",
        "sysdeps/posix/network.cpp",
        "sysdeps/stat.h",
        "sysdeps/uio.h",
        "sysdeps_unix.cpp",
        "tls/adb_ca_list.cpp",
        "tls/include/adb/tls/adb_ca_list.h",
        "tls/include/adb/tls/tls_connection.h",
        "tls/tls_connection.cpp",
        "transport.cpp",
        "transport.h",
        "transport_fd.cpp",
        "types.cpp",
        "types.h",
        "version/platform_tools_version.h",
        "version/build/version.h",
    ],
    local_defines = ["ADB_HOST=1"],
    includes = [
        ".",
        "diagnose_usb/include",
        "incfs",
        "crypto/include",
        "libcrypto_utils/include",
        "pairing_auth/include",
        "pairing_connection/include",
        "tls/include",
        "version",
    ],
    copts = [
        "-Wno-inconsistent-missing-override",
        "-Wno-thread-safety-attributes",
        "-Wno-thread-safety-analysis",
    ],
    cxxopts = COPTS + [
        "-fno-exceptions",
        "-std=c++20"
    ],
    deps = [
        "@boringssl//:crypto",
        "@boringssl//:ssl",
        "@brotli//:brotlidec",
        "@brotli//:brotlienc",
        "@libopenscreen",
        "@libusb",
        "@libzip",
        "@lz4//:lz4_frame",
        "@protobuf//:protobuf",
        "@protobuf//src/google/protobuf/io",
        "//libbase",
        "//libcutils",
        ":libadb_cc_protos",
    ],
    linkopts = [
        "-llzma"
    ],
    features = ["-layering_check"], # Incompatible with libzip cmake build
)
